
package com.mancj.slideup;

import ohos.agp.components.Component;
import ohos.agp.utils.Rect;
import ohos.multimodalinput.event.TouchEvent;

/**
 * Internal
 *
 * @author pa.gulko zTrap (12.07.2017)
 */
class Internal {
    /**
     * * The constant sRect
     */
    private static Rect sRect = new Rect();

    /**
     * Check non null *
     *
     * @param obj     obj
     * @param message message
     */
    static void checkNonNull(Object obj, String message) {
        if (obj == null) {
            throw new NullPointerException(message);
        }
    }

    /**
     * Is up event in view boolean
     *
     * @param view              view
     * @param event             event
     * @param locationOnScreenX location on screen x
     * @param locationOnScreenY location on screen y
     * @return the boolean
     */
    static boolean isUpEventInView(Component view, TouchEvent event, int locationOnScreenX, int locationOnScreenY) {
        Rect componentPosition = view.getComponentPosition();
        int translationX = (int) view.getTranslationX();
        int translationY = (int) view.getTranslationY();
        sRect = new Rect(componentPosition.left + translationX, componentPosition.top + translationY,
                componentPosition.right + translationX, componentPosition.bottom + translationY);
        boolean include = sRect.isInclude((int) event.getPointerPosition(0).getX() - locationOnScreenX, (int) event.getPointerPosition(0).getY() - locationOnScreenY);
        LogUtil.info("isUpEventInView", include + " " + " Rect: " + sRect.toString());
        return include;
    }
}
